/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package grest.view;

import java.awt.Component;
import java.awt.Container;
import java.awt.FocusTraversalPolicy;
import java.util.ArrayList;

/**
 *
 * @author santiago
 */
public class TabPolicy extends FocusTraversalPolicy {

   private ArrayList<Component> listaCom = new ArrayList<Component>();

   public void addIndexedComponent(Component component) {
        listaCom.add(component);
   }

   @Override
   public Component getComponentAfter(Container aContainer, Component aComponent) {
        int atIndex = listaCom.indexOf(aComponent);
        int nextIndex = (atIndex + 1) % listaCom.size();
        return listaCom.get(nextIndex);
   }

   @Override
   public Component getComponentBefore(Container aContainer,
         Component aComponent) {
        int atIndex = listaCom.indexOf(aComponent);
        int nextIndex = (atIndex + listaCom.size() - 1) %
                listaCom.size();
        return listaCom.get(nextIndex);
   }

   @Override
   public Component getFirstComponent(Container aContainer) {
        return listaCom.get(0);
   }

    @Override
    public Component getLastComponent(Container aContainer) {
        return listaCom.get(listaCom.size()-1);
    }

    @Override
    public Component getDefaultComponent(Container aContainer) {
        return listaCom.get(0);
    }
}
